// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   other_register_ok.java

package qcs.qcs;

import com.jspsmart.upload.*;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class other_register_ok extends HttpServlet
{

	public other_register_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			nseer_db_backup1 qcs_db = new nseer_db_backup1(dbApplication);
			if (qcs_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				mySmartUpload.initialize(pageContext);
				String file_type = getFileLength.getFileType((String)session.getAttribute("unit_db_name"));
				long d = getFileLength.getFileLength((String)session.getAttribute("unit_db_name"));
				mySmartUpload.setMaxFileSize(d);
				mySmartUpload.setAllowedFilesList(file_type);
				try
				{
					mySmartUpload.upload();
					String file_name[] = new String[mySmartUpload.getFiles().getCount()];
					Date now = new Date();
					SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
					String time = formatter.format(now);
					String apply_id = NseerId.getId(getClass().getResource("").toString(), (String)dbSession.getAttribute("unit_db_name"));
					for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
					{
						SmartFile file = mySmartUpload.getFiles().getFile(i);
						if (file.isMissing())
						{
							file_name[i] = "";
						} else
						{
							int filenum1 = count.read((String)dbSession.getAttribute("unit_db_name"), "qcsAttachmentcount");
							count.write((String)dbSession.getAttribute("unit_db_name"), "qcsAttachmentcount", filenum1);
							file_name[i] = (new StringBuilder(String.valueOf(filenum1))).append(file.getFileName()).toString();
							file.saveAs((new StringBuilder(String.valueOf(path))).append("qcs/file_attachments/").append(filenum1).append(file.getFileName()).toString());
						}
					}

					String product_id = mySmartUpload.getRequest().getParameter("product_id");
					String product_name = mySmartUpload.getRequest().getParameter("product_name");
					String demand_amount = mySmartUpload.getRequest().getParameter("demand_amount");
					String amount_unit = mySmartUpload.getRequest().getParameter("amount_unit");
					String stock_name = mySmartUpload.getRequest().getParameter("stock_name");
					String register = mySmartUpload.getRequest().getParameter("register");
					String register_id = mySmartUpload.getRequest().getParameter("register_id");
					String register_time = mySmartUpload.getRequest().getParameter("register_time");
					String bodya = new String(mySmartUpload.getRequest().getParameter("other_reason").getBytes("UTF-8"), "UTF-8");
					String other_reason = exchange.toHtml(bodya);
					String bodyab = new String(mySmartUpload.getRequest().getParameter("remark").getBytes("UTF-8"), "UTF-8");
					String remark = exchange.toHtml(bodyab);
					String sqla = (new StringBuilder("insert into qcs_apply(apply_id,remark,register,register_id,register_time,reason) values ('")).append(apply_id).append("','").append(remark).append("','").append(register).append("','").append(register_id).append("','").append(register_time).append("','8')").toString();
					qcs_db.executeUpdate(sqla);
					sqla = (new StringBuilder("insert into qcs_apply_details(apply_id,stock_name,product_id,product_name,amount_unit,demand_amount,other_reason,reason,attachment1,label) values ('")).append(apply_id).append("','").append(stock_name).append("','").append(product_id).append("','").append(product_name).append("','").append(amount_unit).append("','").append(demand_amount).append("','").append(other_reason).append("','8','").append(file_name[0]).append("','01')").toString();
					qcs_db.executeUpdate(sqla);
					response.sendRedirect("qcs/qcs/other_register_ok.jsp?finished_tag=0");
					qcs_db.commit();
					qcs_db.close();
				}
				catch (Exception ex)
				{
					ex.printStackTrace();
					response.sendRedirect("qcs/qcs/other_register_ok.jsp?finished_tag=1");
				}
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
